package com.check.operation.service;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TableLayout;
import android.widget.TextView;

import com.check.operation.R;
import com.check.operation.model.Operation;

public class SsxxAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater;
	private List<Operation> cws;
	private int index = -1;

	public SsxxAdapter(LayoutInflater layoutInflater) {
		super();
		this.layoutInflater = layoutInflater;
	}

	@Override
	public int getCount() {
		return cws.size();
	}

	@Override
	public Operation getItem(int position) {
		return cws.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		Operation operation = getItem(position);
		ViewHolder holder = null;

		if (view == null) {
			view = layoutInflater.inflate(R.layout.ssxx, null);
			holder = new ViewHolder();
			holder.ssmc = (TextView) view.findViewById(R.id.ssmc);
			holder.zdys = (TextView) view.findViewById(R.id.zdys);
			holder.ssbw = (TextView) view.findViewById(R.id.ssbw);
			holder.ssfj = (TextView) view.findViewById(R.id.ssfj);
			holder.sstc = (TextView) view.findViewById(R.id.sstc);
			holder.sszt = (TextView) view.findViewById(R.id.sszt);
			holder.sstab = (TableLayout) view.findViewById(R.id.sstab);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		if (index == position) {
			holder.sstab.setBackgroundResource(R.color.紫色);
		} else {
			holder.sstab.setBackgroundResource(R.color.白色);
		}

		holder.operation = operation;
		holder.ssmc.setText(operation.order_name);
		holder.zdys.setText(operation.emp_name);
		holder.ssbw.setText(operation.op_position_name);
		holder.ssfj.setText(operation.op_room_name);
		holder.sstc.setText(operation.op_sort);
		holder.sszt.setTextColor(view.getResources().getColor(R.color.黑色));

		if ("i".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("进入术前室");
		} else if ("s".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("送手术室");
		} else if ("j".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("进入手术室");
		} else if ("k".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("TIME OUT");
		} else if ("f".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("手术结束");
		} else if ("m".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("进入复苏室");
		} else if ("l".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("离开手术室");
		} else if ("h".equals(operation.process_status)) {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.绿色));
			holder.sszt.setText("回到病房");
		} else {
			holder.sszt.setTextColor(view.getResources().getColor(R.color.红色));
			holder.sszt.setText("错误状态");
		}
		return view;
	}

	static class ViewHolder {
		TextView ssmc;
		TextView zdys;
		TextView ssbw;
		TextView ssfj;
		TextView sstc;
		TextView sszt;
		TableLayout sstab;
		Operation operation;
	}

	public List<Operation> getCws() {
		return cws;
	}

	public void setCws(List<Operation> cws) {
		this.cws = cws;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

}
